package com.sphd.education.activitys;

import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.design.widget.TextInputLayout;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import com.android.volley.AuthFailureError;
import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.sphd.education.EducationApplication;
import com.sphd.education.R;
import com.sphd.education.base.BaseActivity;
import com.sphd.education.info.MyInfo;
import com.sphd.education.modle.EducationUrl;
import com.sphd.education.utils.ToastUtils;

import org.litepal.crud.DataSupport;

import java.util.HashMap;
import java.util.Map;

import butterknife.Bind;
import butterknife.ButterKnife;
/*
* 反馈信息界面
* */
public class FeedBackActivity extends BaseActivity {

    @Bind(R.id.toolbar)
    Toolbar toolbar;
    @Bind(R.id.feedback)
    EditText feedback;
    @Bind(R.id.feedback_textinputlayout)
    TextInputLayout feedbackTextinputlayout;
    @Bind(R.id.ok_update)
    Button ok;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_feed_back);
        ButterKnife.bind(this);
        setSupportActionBar(toolbar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();//这是自带的箭头的返回的监听
            }
        });
        initView();
    }

    @Override
    public void initView() {
        ok.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                sendMessage();
            }
        });
    }

    private void sendMessage() {
        Log.e("url",EducationUrl.HttpTitle + EducationUrl.MyFeedBack);
        StringRequest stringRequest =new StringRequest(Request.Method.POST,EducationUrl.HttpTitle + EducationUrl.MyFeedBack,
                new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {
                Log.e("message",response);
                if (response.equals("yes")){
                    feedback.setText("");
                    ToastUtils.MyToast(FeedBackActivity.this,"反馈成功，谢谢！");
                    finish();
                }else if (response.equals("no")){
                    ToastUtils.MyToast(FeedBackActivity.this,"反馈失败，请重试。");
                }
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {

            }
        }){
            @Override
            protected Map<String, String> getParams() throws AuthFailureError {
                MyInfo myInfo = DataSupport.findLast(MyInfo.class);
                Map<String, String> map=new HashMap<>();
                map.put("id",myInfo.getUserid()+"");
                map.put("suggest",feedback.getText().toString().trim());
                Log.e("Map=",map.toString());
                return map;
            }
        };
        EducationApplication.getRequestQueue().add(stringRequest);
    }

    @Override
    public void findViewById() {

    }

    @Override
    public void myNet() {

    }
}
